<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<?php

	if ( (  ($_FILES["Filedata"]["type"] == "image/gif") || ($_FILES["Filedata"]["type"] == "image/jpeg") 
		|| ($_FILES["Filedata"]["type"] == "image/pjpeg")  )
			&& ($_FILES["Filedata"]["size"] < 200000) ){
  				if ($_FILES["Filedata"]["error"] > 0){
    				echo '<script type="text/javascript">alert("上传文件错误");</script>';
					exit();
   				}
				else{
					$path = './avatar_origin/'. $_FILES['Filedata']['name'];
					move_uploaded_file($_FILES['Filedata']['tmp_name'],$path);
				//portrait路径写入cookie
					$portrait = $_FILES['Filedata']['name'];
					SetCookie("PORTRAIT", $portrait,time()+600);

					echo '<script type="text/javascript">alert("上传成功");</script>';
					echo '<script type="text/javascript">window.parent.hideLoading();window.parent.buildAvatarEditor("'.$portrait.'","'.$path.'","photo");</script>';

				}
	}else{
		echo '<script type="text/javascript">alert("对不起, 上传失败");
			window.location.href = \"../portrait.php\";
		</script>';
	}
?>
</body>
</html>